/**
 * Created by yunpeng on 2015/1/15.
 */
/**
 * Created by yunpeng on 2014/12/4.
 */
var url='/auth/lifeService/GoodsOrdersList';
if(usertype==1){
    url = '/auth/lifeService/GoodsOrdersList?lid='+lid;
}
$('#orderGoods').datagrid({
    url:url,
    //border : false,
    rownumbers: true,
    idField : 'ulid',
    pagination : true,
    sortName : 'createtime',//默认排序的列
    sortOrder: 'desc',
    pageSize : 10,
    pageList : [ 10, 20, 40, 80 ],
    fitColumns : true,
    fit : true,
    checkOnSelect : false,
    selectOnCheck : true,
    striped: true,//条纹交替
    nowrap : false,
    columns:[[
        {field:'',checkbox:true},
        {field:'pic',title:'',width:0,align:'center',
            formatter: function(value,row,index){
                var src = '/'+value;
                return '<img src="'+src+'" style="width:50px;" />';
            }
        },
        {field:'phone',title:'客户手机',width:100,align:'center'
            //styler: function(value,row,index){
            //    return 'background-color:#CAE1FF;border-color:#FFFFFF';
            //}
        },
        {field:'buyer_email',title:'买家支付宝账号',width:100,align:'center'
            //styler: function(value,row,index){
            //    return 'background-color:#CAE1FF;border-color:#FFFFFF';
            //}
        },
        {field:'out_trade_no',title:'订单号',width:100,align:'center'
            //styler: function(value,row,index){
            //    return 'background-color:#CAE1FF;border-color:#FFFFFF';
            //}
        },
        {field:'integral',title:'客户积分',width:90,align:'center'
            //styler: function(value,row,index){
            //    return 'background-color:#CAE1FF;border-color:#FFFFFF';
            //}
        },
        {field:'img',title:'产品',width:50,align:'center',
            formatter: function(value,row,index){
                var src = '/'+value;
                return '<img src="'+src+'" style="width:50px;" />';
            }
        },
        {field:'gname',title:'商品名称',width:70,align:'center'},
        {field:'price',title:'价格/元',width:70,align:'center'},
        {field:'createtime',title:'下单时间',width:130,align:'center',
            styler: function(value,row,index){
                return 'color:red;';
                // 此方法可以返回一个预定义的css类和内联样式
                // return {class:'c1',style:'color:red'}
            }
        },
        {field:'isused',title:'使用状态',width:100,align:'center',
            formatter: function(value,row,index){
                var txt = '未使用';
                if(value==1){
                    txt = '<span style="color: orangered">已使用</span>';
                }
                return txt;
            }
        },
        {field:'industry',title:'商品类型',width:70,align:'center'},
        {field:'trade_no',title:'支付宝交易号',width:100,align:'center'},
        {field:'trade_status',title:'交易状态',width:100,align:'center'},
        {field:'total_fee',title:'付款金额/元',width:100,align:'center'},
        {field:'gmt_create',title:'交易创建时间',width:100,align:'center'},
        {field:'gmt_payment',title:'交易付款时间',width:100,align:'center'}

    ]],
    toolbar : '#ordertb'
});


function searchBusList(){
    //alert($('#phone').textbox('getText')+'  '+$('#phone').textbox('getValue'));
    $('#orderGoods').datagrid('load',{
        orDate1: $('#orDate1').datebox('getValue'),
        orDate2: $('#orDate2').datebox('getValue'),
        phone: $('#phone').textbox('getValue')
    });
}


function updateStatus(){
    var rows = $('#orderGoods').datagrid('getChecked');
    if (rows.length == 1) {
        $.messager.confirm('确认', '是否设置为已使用状态？', function(b) {
            if (b) {
                var ids = null;
                $.ajax({
                    url : '/auth/lifeService/updateStatus',
                    data : {
                        gid : rows[0].ulid
                    },
                    type:'POST',
                    dataType : 'json',
                    success : function(data) {
                        if(data==true){
                            $('#orderGoods').datagrid('reload');
                            $('#orderGoods').datagrid('uncheckAll');// 取消选中的所有记录
                            showMsg('修改成功！');
                        }else{
                            showMsg('修改失败！');
                        }
                    }
                });
            }
        });
    } else {
        $.messager.alert('提示', '请选择1条记录', 'error');
    }
}

function showMsg(msg){
    $.messager.show({
        title:'提示',
        msg:msg,
        timeout:2000,
        showType:'fade'
    });

}